package com.wz.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
//若要定制一些功能，只要写一个组件 ，然后将其交给SpringBoot它会帮你自动装配
    public class MyMvcConfig implements WebMvcConfigurer {

    @Override
    //添加视图控制器   不经过Contorller直接实现页面跳转
    public void addViewControllers(ViewControllerRegistry registry) {
        // registry.addViewController("@RequestMapping的路径").setViewName("页面地址");
        registry.addViewController("/register.html").setViewName("register");
        registry.addViewController("/").setViewName("login");
        //请求:/login.html,进入:login.html
        registry.addViewController("/login.html").setViewName("login");
        //请求:/index.html,进入:index.html
        registry.addViewController("/main.html").setViewName("index");

    }

 @Override
        public void addInterceptors(InterceptorRegistry registry) {
            //注册TestInterceptor拦截器
                registry.addInterceptor(new LoginHandlerInterceptor())
                        .addPathPatterns("/**")
                        .excludePathPatterns(
                                "/",
                                "/login.html",
                                "/login",
                                "/register.html",
                                "/register",
                                "/static/**",
                                "/css/**",
                                "/font-awesome/**",
                                "/images/**",
                                "/img/**",
                                "/js/**"
                                        );
                                         }
}
